package net.toocruel.iqismart.web.handler;

import org.apache.commons.lang.StringUtils;
import org.springframework.security.core.Authentication;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Description
 * @Auther sty
 * @createTime 2018/5/6 下午11:37
 */
@Component
public class LogoutSuccessHandler implements org.springframework.security.web.authentication.logout.LogoutSuccessHandler {
    @Override
    public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {
        String referer = request.getHeader("referer");
        if(StringUtils.isNotBlank(referer)){
            if(referer.contains("/admin")){
                response.sendRedirect("/admin");
            }
        }else{
            response.sendRedirect("/");
        }

        return;
    }
}
